package com.uci.scheduleshare.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import android.util.Log;

public class JulianDay {
	public static int toDayNumber(String j) {
		int jDay = Integer.parseInt(j);
		jDay = jDay - 1721119;
		int year = (4 * jDay - 1) / 146097;
		jDay = 4 * jDay - 1 - 146097 * year;
		int day = jDay / 4;
		jDay = (4 * day + 3) / 1461;
		day = 4 * day + 3 - 1461 * jDay;
		day = (day + 4) / 4;
		int month = (5 * day - 3) / 153;
		day = 5 * day - 3 - 153 * month;
		day = (day + 5) / 5;
		year = 100 * year + jDay;
		if (month < 10) {
			month = month + 3;
		} else {
			month = month - 9;
			year = year + 1;
		}
		Calendar calendar = new GregorianCalendar(year, month - 1, day);		
		return calendar.get(Calendar.DAY_OF_WEEK);
	}
}
